Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint] prevent async Promise constructor mistakes #110349

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Aug 26, 2021

After fixing #109560 I did a little searching and found many cases where we are passing async functions to the Promise constructor without handling the potential of a rejected promise being created by said async function. This PR implements a custom ESLint rule which finds such situations and fixes them by wrapping the body of the function in a try/catch and routing errors caught to reject().

I don't think this produces great code, but it's an improvement over having unhandled promise rejections.

In #109565 I had manually fixed each violation and detailed some strategies for fixing this type of problem for those who are curious, but it felt like I was prescribing a code style in places and felt like we should really prevent this happening in the future with an ESLint rule. Thankfully, my work in #110161 helped me feel more confident in writing fixes like this.

@spalger spalger added Team:Operations Team label for Operations Team v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v7.15.0 v7.16.0 labels Aug 26, 2021
@spalger spalger marked this pull request as ready for review August 31, 2021 05:06
@spalger spalger requested a review from a team August 31, 2021 05:06
@spalger spalger requested a review from a team as a code owner August 31, 2021 05:06
@spalger spalger requested a review from a team August 31, 2021 05:06
@spalger spalger requested review from a team as code owners August 31, 2021 05:06
@spalger spalger requested a review from a team August 31, 2021 05:06
@spalger spalger requested review from a team as code owners August 31, 2021 05:06
@spalger spalger requested a review from a team August 31, 2021 05:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

Copy link
Contributor

@matschaffer matschaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on behalf of @elastic/stack-monitoring-ui - the changes look good and might even fix some of the error handling issues we've had come up with the logstash pipeline view via SDH.

Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alerting changes LGTM!

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app services changes lgtm

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one note.

Copy link
Member

@sabarasaba sabarasaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack management changes LGTM!

Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps/* and maps_ems/* changes ok. thx!

@timroes timroes removed the request for review from a team August 31, 2021 14:57
@spalger spalger requested a review from a team as a code owner August 31, 2021 15:59
Copy link
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,

  • I searched for security_solution and saw the two areas that were fixed.

@spalger spalger enabled auto-merge (squash) August 31, 2021 16:21
@spalger spalger added the auto-backport Deprecated - use backport:version if exact versions are needed label Aug 31, 2021
Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review LGTM for @elastic/kibana-vis-editors files

@spalger
Copy link
Contributor Author

spalger commented Aug 31, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
indexManagement 1.3MB 1.3MB +80.0B
ml 6.0MB 6.0MB +300.0B
visTypeTable 104.0KB 104.0KB +32.0B
visTypeVislib 564.8KB 564.9KB +40.0B
total +452.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dataVisualizer 16.2KB 16.2KB +40.0B
fileUpload 23.6KB 23.7KB +40.0B
maps 78.1KB 78.2KB +40.0B
mapsEms 10.9KB 10.9KB +40.0B
total +160.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@spalger spalger merged commit 72f6700 into elastic:master Aug 31, 2021
@spalger spalger deleted the implement/no-hidden-promise-constructor-rejections branch August 31, 2021 21:55
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 31, 2021
Co-authored-by: spalger <spalger@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
7.14 Commit could not be cherrypicked due to conflicts
7.15 Commit could not be cherrypicked due to conflicts
7.x

Successful backport PRs will be merged automatically after passing CI.

To backport manually run:
node scripts/backport --pr 110349

spalger pushed a commit to spalger/kibana that referenced this pull request Aug 31, 2021
Co-authored-by: spalger <spalger@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts
spalger pushed a commit to spalger/kibana that referenced this pull request Aug 31, 2021
Co-authored-by: spalger <spalger@users.noreply.github.com>
# Conflicts:
#	src/plugins/charts/public/services/active_cursor/use_active_cursor.test.ts
#	x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts
#	x-pack/plugins/task_manager/server/task_scheduling.ts
spalger added a commit that referenced this pull request Sep 1, 2021
…110728)

* [eslint] prevent async Promise constructor mistakes (#110349)

Co-authored-by: spalger <spalger@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts

* autofix additional violation

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
spalger added a commit that referenced this pull request Sep 1, 2021
…110731)

* [eslint] prevent async Promise constructor mistakes (#110349)

Co-authored-by: spalger <spalger@users.noreply.github.com>
# Conflicts:
#	src/plugins/charts/public/services/active_cursor/use_active_cursor.test.ts
#	x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts
#	x-pack/plugins/task_manager/server/task_scheduling.ts

* update yarn.lock file

* add @babel/generator dependency

* autofix additional violation

* update yarn.lock

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Sep 2, 2021
…110727)

* [eslint] prevent async Promise constructor mistakes (#110349)

Co-authored-by: spalger <spalger@users.noreply.github.com>

* autofix one more violation

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Operations Team label for Operations Team v7.14.0 v7.15.0 v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.